/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.ui.customize;

import java.awt.Font;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import lineage.util.Util;

/**
 * 用于使用第三方字体.
 * 
 * @version 2014年2月11日下午12:28:31
 * @author jrwz
 */
public final class L1Font {
    private static String fontpath = "./fonts/";
    private static File file = new File(fontpath + "msyh.ttc"); // 微软雅黑字体
    private static Font _font;

    public L1Font() {
    }

    /**
     * 初始化.
     */
    public static void init() {
        if (!file.exists()) {
            Util.message("file not found(" + file + ")");
            return;
        }
        try {
            FileInputStream fi = new FileInputStream(file);
            BufferedInputStream fb = new BufferedInputStream(fi);
            _font = Font.createFont(Font.TRUETYPE_FONT, fb);
        } catch (FileNotFoundException e) {
            Util.message(e.getMessage());
        } catch (Exception e) {
            Util.message(e.getMessage());
        }
    }

    /**
     * 取得字体.
     * 
     * @return 字体
     */
    public static Font getFont() {
        return _font;
    }

    /**
     * 设置字体.
     * 
     * @param font
     *            - 字体
     */
    public static void setFont(Font font) {
        _font = font;
    }

    /**
     * 设置字体.
     * 
     * @param style
     *            - 样式(0:正常,1:粗体)
     * @param size
     *            - 字号
     */
    public static void setFont(int style, float size) {
        _font = _font.deriveFont(style, size);
    }
}
